package com.meilai.project.controller.web.system;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.meilai.project.dto.CommonResult;
import com.meilai.project.dto.system.MediaTypeClassificationDTO;
import com.meilai.project.entity.system.MediaTypeClassification;
import com.meilai.project.service.system.MediaTypeClassificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 * 媒体类型分类表 前端控制器
 * </p>
 *
 * @author xhy
 * @since 2022-05-20
 */
@RestController
@RequestMapping("/api/web/mediaTypeClassification")
public class WebMediaTypeClassificationController {

    @Autowired
    private MediaTypeClassificationService mediaTypeClassificationService;

    @GetMapping("/page")
    public CommonResult page(@RequestParam("page") Integer page,
                             @RequestParam("page_size") Integer page_size,
                             @RequestParam(value = "name", required = false) String name) {
        return new CommonResult().success(mediaTypeClassificationService.page(page, page_size, name));
    }

    @PostMapping("/save")
    public CommonResult save(@RequestBody MediaTypeClassificationDTO dto) {
        return new CommonResult().success(mediaTypeClassificationService.save(dto));
    }

    @PostMapping("/edit")
    public CommonResult edit(@RequestBody MediaTypeClassificationDTO dto) {
        return new CommonResult().success(mediaTypeClassificationService.edit(dto));
    }

    /**
     * 获取select选择项目数据 估计媒体类型的rid
     *
     * @param media_type_id
     * @return
     */
    @GetMapping("/get-list-by-media-type-id")
    public CommonResult getListByMediaTypeId(@RequestParam("media_type_id") Long media_type_id) {
        return new CommonResult().success(mediaTypeClassificationService.list(media_type_id));
    }

    @DeleteMapping("/remove")
    public CommonResult remove(@RequestParam("id") Long id) {
        return new CommonResult().success(mediaTypeClassificationService.update(Wrappers.<MediaTypeClassification>lambdaUpdate().set(MediaTypeClassification::getDeleted_at, LocalDateTime.now()).eq(MediaTypeClassification::getId, id)));
    }
}

